#!/bin/bash

# 更新镜像站
reflector --country 'China'  > /etc/pacman.d/mirrorlist

# 设置时区
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
hwclock --systohc

# 设置区域和本地化
echo "en_US.UTF-8 UTF-8" >>/etc/locale.gen
echo "zh_CN.UTF-8 UTF-8" >>/etc/locale.gen
locale-gen
echo "LANG=en_US.UTF-8" >>/etc/locale.conf

# 设置主机名
read -p "请输入要设置的电脑主机名：" host_name
echo "$host_name" >>/etc/hostname

# 本地主机名解析
echo "127.0.0.1        localhost" >>/etc/hosts
echo "::1              localhost" >>/etc/hosts
echo "127.0.1.1        $host_name.localdomain        $host_name" >>/etc/hosts

# 启动引导配置
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB
grub-mkconfig -o /boot/grub/grub.cfg

# 启动网络服务
systemctl enable NetworkManager.service
systemctl enable ModemManager.service
systemctl enable sshd.service

# 设置忽略大小写
echo "set completion-ignore-case on" >>/etc/inputrc

# 设置别名
echo "alias archlinux='neofetch'" >~/.bashrc

# 设置软件源
cd
cp archlinux/pacman.conf /etc/pacman.conf -f
cp archlinux/mirrorlist /etc/pacman.d/mirrorlist -f
cd
rm -rf archlinux/

# 设置 root 密码
echo "请设置root用户密码："
passwd

# 更新系统
pacman -Syyu --noconfirm

# 安装必要软件
pacman -S --noconfirm sudo 

# 退出 chroot 环境
# exit
